import demo1.demo2.test.PeopleCenter2;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: DELL
 * Date: 2023-04-23
 * Time: 17:13
 */
public class RunClass {
    public static void main1(String[] args) {
        // 创建一个启动类, 包含 main方法即可
        // 获取上下文对象
//        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
//        // 获取指定 Bean 对象
//        Student student = context.getBean("student", Student.class);
//        // 使用 Bean 对选哪个
//        student.fun();
//        // 获取指定 Bean 对象
//        Student student2 = (Student) context.getBean("student");
        // 使用 Bean 对象

        // 获取指定 Bean 对象
//        Student student1 = context.getBean(Student.class);
    }

    public static void main2(String[] args) {
        // 1. 获取 Spring 容器(上下文对象)
//        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
//        // 2. 获取 Bean 对象
//        User user =  context.getBean("user1",User.class);
//        // 3. 使用 Bean 对象(调用方法验证)
//        System.out.println(user.getUsername());

//        ApplicationContext context1 = new ClassPathXmlApplicationContext("spring-config.xml");
//        // 2. 获取 Bean 对象
//        ControllerStudent student1 =  context.getBean("controllerStudent",ControllerStudent.class);
//        // 3. 使用 Bean 对象(调用方法验证)
//        student1.fun();

//        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
//        demo1.demo2.test.ControllerStudent controllerStudent = context.getBean("controllerStudent", demo1.demo2.test.ControllerStudent.class);
//        controllerStudent.fun();

//        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
//        User user = context.getBean("User2", User.class);
//        System.out.println(user.getUsername());
    }




    public static void main3(String[] args) {
//        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
//        StudentController2 student =  context.getBean("studentController2", StudentController2.class);
//        student.fun();
    }

    public static void main4(String[] args) {
//        ApplicationContext context = new ClassPathXmlApplicationContext("spring-config.xml");
//        PeopleController1 controller1 = context.getBean("peopleController1", PeopleController1.class);
//        System.out.println("对象 A 修改之后 name : " + controller1.getPeople().getName());
//
//        PeopleController2 controller2 = context.getBean("peopleController2", PeopleController2.class);
//        System.out.println("对象 B 读取到的 name : " +controller2.getPeople().getName());
    }

    public static void main(String[] args) {
        // 由于 ApplicationContext 里面没有销毁方法, 因此只能用父类 ClassPathXmlApplicationContext
        ClassPathXmlApplicationContext context =
                new ClassPathXmlApplicationContext("spring-config.xml");

        PeopleCenter2 peopleCenter2 =
                context.getBean("peopleCenter2", PeopleCenter2.class);

        peopleCenter2.fun();
        context.destroy();
    }
}
